package com.demo.datasource;

import javax.sql.DataSource;

import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.alibaba.druid.pool.DruidDataSource;

@Configuration
public class DoubleDatasource {

	@Bean(name = "testDataSource")
	@Primary
	@ConfigurationProperties(prefix = "spring.datasource.test")
	public DataSource primaryDataSource() {
		System.out.println("-------------------- SpringDataSource init ---------------------");
		return DataSourceBuilder.create().build();
	}

	@Bean(name = "druidDataSource")
	@ConfigurationProperties(prefix = "spring.datasource.druid")
	public DataSource secondaryDataSource() {
		System.out.println("-------------------- DruidDataSource init ---------------------");
		return new DruidDataSource();
	}
}
